Quiz: Deduce the Outputs
In this lesson your concepts will be evaluated through a quiz.
Choose one correct answer
12
What do the following two functions task1 and task2 return for sl equals to {78, 34, 643, 12, 90, 492, 13, 2}?
func task1(sl []int) (n int) {
n = math.MinInt32
for _, v := range sl {
if v > n {
n = v
}
}
return
}
func task2(sl [] int) (n int) {
n = math.MaxInt32
for _, v := range sl {
if v < n {
n = v
}
}
return
}
Your Answer
A)Compiler Error
B)
task1 returns 2 and task2 returns 643.
Correct Answer
C)task2 returns 2 and task1 returns 643.
D)
None of the above
Question 12 of 1212 attempted
We hope that you performed well in the quiz. That’s it about the arrays and slices. In the next chapter, we’ll discuss maps in Go.
Solution Review: Reverse a String
Declaration and Initialization